<template>
  <div>
    <el-card  class="box-card" style="margin-top: 20px">
      <div slot="header" class="clearfix" style=" font-size: 14px;">
        <span>审批意见列表</span>
      </div>
      <el-row style="margin-top: 10px;">
        <el-table :data="showOpinionList" border style="width: 100%">
          <el-table-column type="index" label="序号" align="center" width="50">
          </el-table-column>
          <el-table-column prop="taskName" align="center" width="180" label="任务名称">
          </el-table-column>
          <el-table-column prop="createUser" align="center" width="180" label="处理人">
          </el-table-column>
          <el-table-column prop="content" align="center" width="280" label="意见">
          </el-table-column>
          <el-table-column prop="createDate" align="center" width="180" label="处理时间"  type="date" :formatter="dateFormatter">
          </el-table-column>
          <el-table-column prop="name" align="center" label="操作" width="180">
            <template slot-scope="scope">
              <el-button type="text"  @click="viewOpinion(scope.row)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
    </el-card>
    <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" :before-close="handleFormClose">
      <el-form :model="showOpinion" ref="showOpinion">
        <el-form-item label="任务名称"  label-width="120px">
          <el-input v-model="showOpinion.taskName" :disabled="viewHide" placeholder="请输入意见内容" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="处理人"  label-width="120px">
          <el-input v-model="showOpinion.taskName" :disabled="viewHide" placeholder="请输入处理人" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="处理时间"  label-width="120px">
          <el-date-picker
            type="datetime"
            placeholder="选择日期"
            v-model="showOpinion.createDate"
            :disabled="viewHide"
            style="width: 100%;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="意见内容"  label-width="120px">
          <el-input type="textarea" :rows="2" v-model="showOpinion.content" placeholder="请输入审批意见" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-card class="box-card" style="margin-top: 20px;">
      <div slot="header" class="clearfix" style=" font-size: 14px;">
        <span>审批意见</span>
      </div>
      <el-form :model="myOpinion" ref="myOpinion">
        <el-row>
          <el-form-item label="我的意见"  label-width="120px">
            <el-input type="textarea" :rows="2" v-model="myOpinion.content" 
              placeholder="请输入审批意见" autocomplete="off"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
        </el-row>
        <div style="text-align:center;width:100%;">
          <el-button type="primary" @click="doSubmit(false)">保存</el-button>
          <el-button type="success" @click="doSubmit(true)">提交</el-button>
        </div>
      </el-form>
    </el-card>
  </div>
</template>
      
<script>
export default {
  components: {
      projHandleDisplay: require("@/pages/biz/proj/projDisplay/projHandleDisplay.vue").default,
  },
  data() {
    return {
      // 历史审批意见
      showOpinionList: [],
      // 拟态框
      dialogFormVisible: false,
      // 审批意见
      showOpinion: {},
      // 我的审批意见
      myOpinion: {},
    };
  },
  computed: {},
  mounted() {
      // this.init();
  },
  methods: {
    /**
     * 关闭拟态框
     */
    handleFormClose() {
      this.dialogFormVisible = false;
    },
    /**
     * 拟态框可见
     */
    viewOpinion(item) {
      this.dialogFormVisible = true;
      this.showOpinion = item;
    },
    /**
     * tab标签切换
     */
    changeTab() {

    },
    /**
     * 返回
     */
    back(){
      this.$router.push({path:"/proj/projHandleList"});
    },
    init() {
      //合作银行列表
      this.$refs.entBaseComponentDisplay.init(this.entId);
    },
    save(){
      let projHandle= this.$refs.projHandleComponent.getdata();
      let user=JSON.parse(sessionStorage.getItem("user"));
      projHandle.createUserId=user.id;
      projHandle.createUserName=user.realName;
      projHandle.projApplyId=this.projApplyId;
      this.$api.formPost( 'biz/project/doAcceptance',projHandle).then(res => {
        if(res.retHead.code=="0000000"){
              this.projId=res.retBody;
              if (this.projId) {
                this.isProjMate = false;
              }
              this.$message({
                  type: 'success',
                  message: "保存成功！"
              });
          }else{
            
              this.$message({
                  type: 'error',
                  message: res.retHead.message
              });
          }
      });
    },
    submit(){
      let projHandle= this.$refs.projHandleComponent.getdata();
      let user=JSON.parse(sessionStorage.getItem("user"));
      projHandle.createUserId=user.id;
      projHandle.createUserName=user.realName;
      projHandle.workflowCode="005";
      projHandle.projApplyId=this.projApplyId;
      if(!this.projId){
        this.$message({
                      type: 'error',
                      message: "请先保存，再提交",
            });
            return;
      }
      projHandle.id=this.projId;
      this.$api.formPost( 'biz/project/doStart',projHandle).then(res => {
        console.log(res);
            if(res.retHead.code=="0000000"){
                  this.$message({
                      type: 'success',
                      message: "流程启动成功！"
                  });
              }else{
                
                  this.$message({
                      type: 'error',
                      message: res.retHead.message
                  });
              }
          });
    },
    /**
     * 保存
     */
    changeTab(a, b) {
      let tabName = b.target.innerText;
      if ('材料收集' == tabName) {
        this.$refs.projMateComponent.doSaveMateList(this.projId, '1');
      }
    },
    /**
     * 保存或取消我的审批意见
     */
    doSubmit(isSubmit) {
      let params = {};
      let user = JSON.parse(sessionStorage.getItem("user"));
      let conent="1";
      if (this.myOpinion != null) {
        params.myOpinion = this.myOpinion;
      }
      if (this.taskConclusion != null) {
        params.taskConclusion = this.taskConclusion;
        if (this.taskConclusion === "不通过") {
          conent="2";
        }
        if(this.taskConclusion === "退回"){
          conent="3";
        }
      }
      params.taskWorkitemId = this.taskWorkitem.id;
      if (isSubmit) {
        params.isSubmit = "1";
        params.userId =user.id;
        if (this.addSign) {
          params.sign = this.sign;
          params.signUser = this.signUser;
        }
        if (this.isCc) {
          params.cc = this.cc;
          params.ccUser = this.ccUser;
        }
        params.variables = {
          managerA:this.userAB.userA,
          managerB:this.userAB.userB,
          jl:conent,
        };
      }
      

      if (this.taskTemplate != null && this.taskTemplate.isOpinion !== "0") {
        let project={
          id:this.projectId,
          managera:this.userAB.userA,
          managerb:this.userAB.userB
        }
        // 更新项目主表
        this.$api.formPost( "/api/biz/project/doModById",project).then(res => {
          if (res.retHead.code === "0000000") {
            // 先保存意见，再提交流程
            this.$api.post("wf/opinion/save", this.myOpinion).then(res => {
              if (res.status === "0") {
                this.submitMethod(params);
              }
            });
          }
        });
        
      } else {
        this.submitMethod(params);
      }
    },

    /** */
    submitMethod(params) {
      this.$api.post("wf/submit", params).then(res => {
        console.log(res);
        if (res.status === "0") {
          this.handleFormClose();
          this.$message({
            type: "success",
            message: "保存成功!"
          });
          
          if (params.isSubmit) {
            this.$router.push({
              path: "/mywork/taskLog"
            });
          } else {
            this.getBusinessInfo();
          }
        }
      });
    },
  },
  created() {}
};
</script>
<style lang='scss' scoped>
</style>